﻿using System.Collections.Generic;
using System.Globalization;
using System.Text;
using OA.Model;
using OA.Utility;

namespace OA.Bll.Reimbursement
{
    public class ReimbursementDictionaryPresenter : BasePresenter<ReimbursementDictionaryInfo>
    {
        public string SearchComboboxData(JsonReq req)
        {
            string sql = JsonHelper.GetQueryFilterString(req.Options);
            List<ReimbursementDictionaryInfo> list = Manager.GetSearchAll(sql);
            StringBuilder sb = new StringBuilder();
            sb.Append("[");
            sb.Append("{\"id\": \"" + list.Count + 1 + "\", \"text\": \"机票报销单\"},");
            sb.Append("{\"id\": \"" + list.Count + 2 + "\", \"text\": \"出差补助\"},");
            foreach (ReimbursementDictionaryInfo info in list)
            {
                sb.Append("{");
                if (info != null)
                    sb.Append(string.Format("\"id\": \"{0}\", \"text\": \"{1}\"",
                                            info.Id.ToString(CultureInfo.InvariantCulture),
                                            info.ItemNo + " " + info.ItemName));
                sb.Append("},");
            }
            sb.Remove(sb.ToString().Length - 1, 1);
            sb.Append("]");
            return sb.ToString();
        }
    }
}
